const {imgUrl} = getApp().globalData
import { mineApi } from "@/utils/request/api/mine";
Page({
  data: {
    imgUrl: imgUrl + "mine/",
    refresherStatus: false,
    hasMore: true,
    page: 1,
    page_size: 10,
    total: 0,
    list: [],
    
    bkIndex: 0,
    bks: [
      {
        kb: 7,
        money: 1
      },
      {
        kb: 42,
        money: 6
      },
      {
        kb: 105,
        money: 15
      },
      {
        kb: 280,
        money: 40
      },
      {
        kb: 476,
        money: 68
      },
      {
        kb: 686,
        money: 99
      },
      {
        kb: 756,
        money: 108
      },
      {
        kb: 1386,
        money: 198
      },
      {
        kb: 5000,
        money: 700
      },
    ],
    isChecked: true,
    zb: 0,
    now_money: 0
  },
  changeIndex(event) {
    const index = event.currentTarget.dataset.index;
    this.setData({
      bkIndex: index
    });
  },
  changeZb(event) {
    let zb = event.currentTarget.dataset.zb;
    this.setData({
      zb,
      page: 1,
      hasMore: true,
    }, () => {
      this.getList();
    });
  },
  scrolltolower() {
    if (!this.data.hasMore) {
      return;
    }
    let page = this.data.page + 1;
    this.setData({
      page,
    });
    this.getList();
  },
  // 下拉刷新
  handleRefresherRefresh() {
    this.setData({
      refresherStatus: true,
      page: 1,
      hasMore: true,
    });
    this.getList();
  },
  getList() {
    mineApi
      .getCoinList({
        type: this.data.zb,
        page: this.data.page,
        page_size: this.data.page_size,
      })
      .then((res) => {
        let arr = res.data.list;
        arr.map(item => {
          let date = new Date(item.created_at)
          item.created_at = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes();
          return item;
        })
        this.setData({
          list: this.data.page > 1 ? this.data.list.concat(arr) : arr,
          total: res.data.total,
          hasMore: this.data.page * this.data.page_size <= res.data.total,
          refresherStatus: false,
        })
      });
  },
  onLoad(options) {
    const info = wx.getStorageSync('myInfo');
    this.setData({
      now_money: info.coin_balance
    })
  },
  onReady() {
  },
  onShow() {
    this.getList();
  },
  onHide() {
  },
  onUnload() {
  },
  onShareAppMessage() {
    return {
      title: '',
    };
  },
});